﻿using Decoration.Comm;
using Decoration.Models;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace Decoration.Api.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ChartController : ControllerBase
    {
        // GET: api/<ChartController>
        [HttpGet]
        [Route("GetDept")]
        public Result GetDept()
        {
            var SQL = @"select v.DictName,COUNT(*) as'sum'
                                         from Base_UserInfos u inner join vw_dict v 
		                                 on u.DeptId = v.DictValue and DictTypeName='部门'
		                                 group by v.DictName";
            var data = DapperHelper.Query<dynamic>(SQL, new { });

            return new Result() { code = 1, msg = "成功", data = data };
        }
        [HttpGet]
        [Route("GetWeek")]
        public Result GetWeek()
        {
            var SQL = @"	select datename(weekday,CreateTime) as 'weekday'
                                            ,(case when datepart(weekday,CreateTime)=1 then 8 else datepart(weekday,CreateTime) end ) ord
                                            ,count(*) num 
                                            from Base_UserInfos
                                            group by  datename(weekday,CreateTime),(case when datepart(weekday,CreateTime)=1 then 8 else datepart(weekday,CreateTime) end ) 
                                            order by ord";
            var data = DapperHelper.Query<dynamic>(SQL, new { });

            return new Result() { code = 1, msg = "成功", data = data };
        }
    }
}
